package com.neusoft.neuiotms.dcom.model.incident;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.IncidentRegisterStatus;

import lombok.Getter;
import lombok.Setter;

/**
 * @author WYS
 * @date 2020年8月18日 下午1:30:04
 */
@Getter
@Setter
@Entity
@Table(name = "neuiot_incident_register")
@org.hibernate.annotations.Table(appliesTo = "neuiot_incident_register", comment = "事件创建与分发表")
public class IncidentRegister extends AbstractAuditModel {

    private static final long serialVersionUID = -7967358753741436384L;

    @Length(max = 255, message = "工作流TaskId不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NOT NULL COMMENT '工作流TaskId'")
    private String taskId;

    @Length(max = 100, message = "事件标题不能超过{max}位")
    @Column(length = 100, nullable = false)
    @Comment("varchar(100) NOT NULL COMMENT '事件标题'")
    private String name;

    @Length(max = 50, message = "工单号不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '工单号'")
    private String workNum;

    @Length(max = 50, message = "配置项Code不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NULL COMMENT '配置项Code'")
    private String objCode;

    @Length(max = 100, message = "配置项名称不能超过{max}位")
    @Column(length = 100, nullable = true)
    @Comment("varchar(100) NULL COMMENT '配置项名称'")
    private String objName;

    @Length(max = 50, message = "配置项Id不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '配置项ID'")
    private String objId;

    @Length(max = 50, message = "申请人编码不能超过{max}位")
    @Column(length = 50, nullable = true)
    @Comment("varchar(50) NOT NULL COMMENT '申请人编码'")
    private String applyUserCode;

    @Length(max = 255, message = "申请人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '申请人名称'")
    private String applyUserName;

    @Length(max = 32, message = "申请方式不能超过{max}位")
    @Column(length = 32, nullable = true)
    @Comment("varchar(32) NULL COMMENT '申请方式：电话、邮件'")
    private String applyType;

    @Length(max = 100, message = "通讯号码不能超过{max}位")
    @Column(length = 100, nullable = true)
    @Comment("varchar(100) NULL COMMENT '通讯号码'")
    private String communicationNumber;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '申请时间'")
    private Date applyTime;

    @Length(max = 50, message = "影响范围不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '影响范围'")
    private String coverageInfluence;

    @Length(max = 50, message = "紧急程度不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '紧急程度'")
    private String urgency;

    @Length(max = 50, message = "优先级不能超过{max}位")
    @Column(length = 50, nullable = false)
    @Comment("varchar(50) NOT NULL COMMENT '优先级'")
    private String priority;

    @Lob
    @Column(columnDefinition = "longtext")
    @Comment("longtext COMMENT '详细说明'")
    private String description;

    @Length(max = 50, message = "分发人编码不能超过{max}位")
    @Column(length = 50, nullable = true)
    @Comment("varchar(50) NOT NULL COMMENT '分发人编码'")
    private String dispatchUserCode;

    @Length(max = 255, message = "分发人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '分发人名称'")
    private String dispatchUserName;

    @Length(max = 50, message = "登记人编码不能超过{max}位")
    @Column(length = 50, nullable = true)
    @Comment("varchar(50) NOT NULL COMMENT '登记人编码'")
    private String registerUserCode;

    @Length(max = 255, message = "登记人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '登记人名称'")
    private String registerUserName;

    @Length(max = 50, message = "事件来源不能超过{max}位")
    @Column(length = 50, nullable = true)
    @Comment("varchar(50) NULL COMMENT '事件来源'")
    private String incidentFrom;

    @Enumerated(EnumType.STRING)
    @Column(length = 20, nullable = true)
    @Comment("varchar(20) NULL COMMENT '状态'")
    private IncidentRegisterStatus status;

    /** 附件列表 **/
    @OneToMany(mappedBy = "incidentRegister", cascade = CascadeType.ALL)
    private List<IncidentRegisterAttachment> attachments = new ArrayList<>();
}
